package com.prototype.mapping {
	import flash.display.BitmapData;
	import flash.utils.Dictionary;
	/**
	 * ...
	 * @author Santiago.J.Elizalde
	 */
	public class TileLibrary {
		
		public static const FLAT:int=1;
		public static const BLOCKED:int = 2;
		public static const WATER_GAP:int = 3;
		public static const WATER_END_LEFT:int = 4;
		public static const WATER_END_RIGHT:int = 13;
		public static const PLATFORM_BEGIN:int = 5;
		public static const PLATFORM_PIECE:int = 6;
		public static const PLATFORM_PIECE_ALT:int = 7;
		public static const PLATFORM_END:int = 8;
		static public const WATER_PLATFORM_BEGIN:int = 9;
		static public const WATER_PLATFORM_PIECE:int = 10;
		static public const WATER_PLATFORM_PIECE_ALT:int = 11;
		static public const WATER_PLATFORM_END:int = 12;
		
		private var tileMap:Dictionary;
		private var templates:Dictionary;
		
		public function TileLibrary() {
			
			tileMap = new Dictionary();
			tileMap["water"] = new BMPTile06();
			tileMap["waterRocks"] = new BMPTile04();
			tileMap["groundTop"] = new BMPTile12();
			tileMap["ground"] = new BMPTile02();
			tileMap["groundEndLeft"] = new BMPTile13();
			tileMap["groundEndRight"] = new BMPTile15();
			tileMap["groundTopEndLeft"] = new BMPTile03();
			tileMap["groundTopEndRight"] = new BMPTile14();
			tileMap["platformEndLeft"] = new BMPTile07();
			tileMap["platformEndRight"] = new BMPTile09();
			tileMap["platformMid_01"] = new BMPTile05();
			tileMap["platformMid_02"] = new BMPTile08();
			tileMap["block"] = new BMPTile01();
			tileMap["plant"] = new BMPTile10();
			tileMap["bush"] = new BMPTile11();
			tileMap["empty"] = new BitmapData(63,63,true,0x000000);
			
			templates = new Dictionary();
			templates[FLAT] = ["waterRocks", "ground", "groundTop"];
			templates[BLOCKED] = ["waterRocks", "ground", "groundTop", "block"];
			templates[WATER_GAP] = ["water"];
			templates[WATER_END_LEFT] = ["waterRocks", "groundEndRight", "groundTopEndRight"];
			templates[WATER_END_RIGHT] = ["waterRocks", "groundEndLeft", "groundTopEndLeft"];
			templates[PLATFORM_BEGIN] = ["waterRocks", "ground", "groundTop", "empty", "empty", "platformEndLeft"];
			templates[PLATFORM_PIECE] = ["waterRocks", "ground", "groundTop", "empty", "empty", "platformMid_01"];
			templates[PLATFORM_PIECE_ALT] = ["waterRocks", "ground", "groundTop", "empty", "empty", "platformMid_02"];
			templates[PLATFORM_END] = ["waterRocks", "ground", "groundTop", "empty", "empty", "platformEndRight"];
			templates[WATER_PLATFORM_BEGIN] = ["water", "empty", "empty", "empty", "platformEndLeft"];
			templates[WATER_PLATFORM_PIECE] = ["water", "empty", "empty", "empty", "platformMid_01"];
			templates[WATER_PLATFORM_PIECE_ALT] = ["water", "empty", "empty", "empty", "platformMid_01"];
			templates[WATER_PLATFORM_END] = ["water", "empty", "empty", "empty", "platformEndRight"];
		}
		
		public function getTileData(name:String):BitmapData {
			return tileMap[name] || tileMap["empty"];
		}
		
		public function getTemplateLine(template:int):Array {
			var line:Array = [];
			var templateList:Array = templates[template] || [];
			for each (var item:String in templateList) {
				line.push(getTileData(item));
			}
			return line;
		}
	}

}